package com.youoor.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.youoor.common.base.BaseDaoImpl;
import com.youoor.common.base.BaseMapper;
import com.youoor.dao.UserDao;
import com.youoor.domain.UserInfo;
import com.youoor.domain.UserInfoQuery;
import com.youoor.persistence.UserInfoMapper;
@Repository("userDao")
public class UserDaoImpl extends BaseDaoImpl<UserInfo,UserInfoQuery,Integer> implements UserDao {
	private static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
	
	@Resource
	private UserInfoMapper userInfoMapper;


	public void setUserInfoMapper(UserInfoMapper userInfoMapper) {
		this.userInfoMapper = userInfoMapper;
	}

	@Override
	public BaseMapper<UserInfo, UserInfoQuery, Integer> getBaseMapper() {
		// TODO Auto-generated method stub
		return userInfoMapper;
	}

	@Override
	public UserInfo verifyUser(String userName, String password) {
		UserInfoQuery query = new UserInfoQuery();
		query.createCriteria().andUsernameEqualTo(userName).andPasswordEqualTo(password);
		List<UserInfo> userInfoList = userInfoMapper.selectByExample(query,null);
		if(userInfoList != null && userInfoList.size() > 0) {
			return userInfoList.get(0);
		}
		return null;
	}

	@Override
	public UserInfo getUserByName(String userName) {
		UserInfoQuery query = new UserInfoQuery();
		query.createCriteria().andUsernameEqualTo(userName);
		List<UserInfo> userInfoList = userInfoMapper.selectByExample(query,null);
		if(userInfoList != null && userInfoList.size() > 0) {
			return userInfoList.get(0);
		}
		return null;
	}

	@Override
	public UserInfo getUserByEmail(String email) {
		UserInfoQuery query = new UserInfoQuery();
		query.createCriteria().andEmailEqualTo(email);
		List<UserInfo> userInfoList = userInfoMapper.selectByExample(query,null);
		if(userInfoList != null && userInfoList.size() > 0) {
			return userInfoList.get(0);
		}
		return null;
	}





}
